package com.zghhost.codedemo.anonymous;

/**
 * @author guohua.zhang 关于java一些匿名写法 随便写的
 */
public class AnonymousTest {
    private static void execute(ASimpleInterface asi){
        asi.talk();
    }

      //这种写法是不适用lambda
//    private static void execute(ASimpleClass asi){
//        asi.talk();
//    }

    public static void main(String[] args){
        //接口的匿名实现
        ASimpleInterface a = new ASimpleInterface(){
            @Override
            public void talk() {
                System.out.println("Hi i'm interface anonymous instance");
            }
        };
        System.out.println(a instanceof ASimpleInterface);
        System.out.println(a instanceof ASimpleClass);
        a.talk();

        //一个匿名的继承自ASimpleClass的实现
        ASimpleInterface b = new ASimpleClass(){
            @Override
            public void talk() {
                System.out.println("Hi i'm class anonymous instance");
                super.talk();
            }
        };
        System.out.println(b instanceof ASimpleInterface);
        System.out.println(b instanceof ASimpleClass);
        b.talk();

        ASimpleInterface c = new ASimpleClass();
        System.out.println(c instanceof ASimpleInterface);
        System.out.println(c instanceof ASimpleClass);
        c.talk();

        execute(() -> {
            System.out.println("123");
        });
    }
}
